<template>
  <smart-table
    :title="problemBankTitle"
    :formList="problemBankFormList"
    :selectUrl="problemBankSelectUrl"
    :insertUrl="problemBankInsertUrl"
    :updateUrl="problemBankUpdateUrl"
    :deleteUrl="problemBankDeleteUrl"
    :exportExcelUrl="problemBankExportUrl"
    :importExcelUrl="problemBankImportUrl"
    :tableColumns="problemBankTableColumns"
    :formButtonCtl="problemBankFormButtonCtl"
    :dialogWidth="60"
    :dialogLabelWidth="labelWidth"
    :formRules="problemBankFormRules" />
</template>

<script>
export default {
  data() {
    return {
      labelWidth: 10,
      //主题
      problemBankTitle: '题库',
      //表单列表
      problemBankFormList: [
        {
          title: '题库名',
          name: 'name',
          type: 'input',
          width: 80,
        },
        {
          title: '描述',
          name: 'description',
          type: 'markdown',
          width: 80,
          hidden: {
            header: true,
          },
        },
        {
          title: '科目',
          name: 'subjectId',
          type: 'select',
          showValue: false,
          width: 80,
          optionList: [],
          key: 'id',
          label: 'name',
        },
        {
          title: '及格分',
          name: 'passScore',
          type: 'number',
          maxNumber: 500,
        },
      ],
      //题库查询路径
      problemBankSelectUrl: 'problemBank/lookProblemBank',
      //题库新增路径
      problemBankInsertUrl: 'problemBank/addProblemBank',
      //题库更新路径
      problemBankUpdateUrl: 'problemBank/updateProblemBank',
      //题库删除路径
      problemBankDeleteUrl: 'problemBank/deleteProblemBank',
      //题库导出路径
      problemBankExportUrl: '/examService/proBank/export',
      //题库导入路径
      problemBankImportUrl: '/examService/proBank/import',
      //表格列
      problemBankTableColumns: [
        {
          title: '题库名',
          name: 'name',
          width: 130,
        },
        {
          title: '科目',
          name: 'subjectName',
          width: 120,
          filters: [],
          filterName: 'name',
        },
        {
          title: '单选题',
          name: 'singleCount',
          width: 120,
        },
        {
          title: '多选题',
          name: 'multiCount',
          width: 120,
        },
        {
          title: '判断题',
          name: 'judgeCount',
          width: 120,
        },
        {
          title: '主观题',
          name: 'subjectiveCount',
          width: 120,
        },
        {
          title: '题总数',
          name: 'problemNum',
          width: 120,
        },
        {
          title: '总分',
          name: 'scoreSum',
          width: 120,
        },
        {
          title: '及格分',
          name: 'passScore',
          width: 120,
        },
        {
          title: '创建时间',
          name: 'createTime',
          width: 180,
        },
        {
          title: '修改时间',
          name: 'updateTime',
          width: 180,
        },
      ],
      //表单按钮控制
      problemBankFormButtonCtl: {
        detailButton: false,
      },
      //表单校验
      problemBankFormRules: {
        name: [
          {
            required: true,
            message: '题库名不得为空!',
            trigger: 'blur',
          },
        ],
        description: [
          {
            required: true,
            message: '描述不得为空!',
            trigger: 'blur',
          },
        ],
        subjectId: [
          {
            required: true,
            message: '科目不得为空!',
            trigger: 'change',
          },
        ],
        passScore: [
          {
            required: true,
            message: '及格分不得为空!',
            trigger: 'blur',
          },
        ],
      },
    }
  },
  mounted() {},
  created() {
    this.initSubjectData()
  },
  methods: {
    initSubjectData() {
      this.$store.dispatch('subject/lookSubjectAll').then((response) => {
        this.problemBankFormList[2].optionList = this.problemBankTableColumns[1].filters = response.data
      })
    },
  },
}
</script>

<style lang="scss" scoped></style>
